/**
 *
 * @param {Array} menuList 后台返回的用户菜单名字数组
 * @param {Array} allRoutes 我们定义的所有路由的配置
 * @returns {Array} 根据后台菜单计算出来的用户routes配置
 */
const recursion = (menuList = [], allRoutes = []) => {
  let userRoutes = [];
  menuList.forEach((item) => {
    allRoutes.forEach((routes) => {
      if (item.name === routes.meta.name) {
        if (item.children && item.children.length > 0) {
          routes.children = recursion(item.children, routes.children);
        }
        userRoutes.push(routes);
      }
    });
  });
  return userRoutes;
};
export default recursion;
